import requests


class AmdDepApi(object):

    def query_adm(self,emp_id,req_header): #查询部门
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/company/department/"+emp_id,
                           headers=req_header)
        return resp

    def add_adm_(self,req_header, req_body):#添加部门
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/company/department",
                             headers=req_header,json= req_body)
        return resp

    def modify_adm(self,emp_id,req_header,req_body):#修改部门
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/company/department/"+emp_id,
                            headers=req_header,json=req_body)
        return resp

    def del_adm(self,emp_id,req_header):#删除部门
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/company/department/"+emp_id,
                              headers=req_header)
        return resp
if __name__ == '__main__':
    amd=AmdDepApi()
    resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                         json={"mobile": "13800000002", "password": "123456"})
    print("登录成功")
    token = resp.json().get("data")
    req_header={"Authorization":token}
    emp_id="1549377675397820416"
    res=amd.query_adm(emp_id,req_header)
    print("查询",res.json())

    req_body={"name": "会飞的猪","code":"3452"}
    res = amd.add_adm_(req_header,req_body)
    print("添加",res.json())

    req_body2={"name": "会飞的狗","code":"3455"}
    res =amd.modify_adm(emp_id,req_header,req_body2)
    print("修改", res.json())

    res=amd.del_adm(emp_id,req_header)
    print("删除", res.json())